import imgLoading from '../assets/images/loading.gif'
/** 加载组件 */
class Cat2DocLoading {
    #loadingDiv = null;
    constructor(parentElement, options) {
        this.#loadingDiv = createLoading(parentElement, options);
    }

    show() {
        this.#loadingDiv.style.display = 'inline-flex';
    }

    hide() {
        this.#loadingDiv.style.display = 'none';
    }
}
/**  */
function createLoading(parentElement, options) {
    let opts = {
        ...{
            url: '',
            label: 'loading...'
        },
        ...options
    }
    let div = document.createElement('div');
    div.className = 'c2d-loading';
    div.style.zIndex = '998';
    div.style.position = 'absolute'
    div.style.left = '0px';
    div.style.top = '0px';
    div.style.right = '0px';
    div.style.bottom = '0px';
    div.style.display = 'none';
    div.appendChild(createLoadingIcon(opts));
    div.appendChild(createLoadingLabel(opts));
    parentElement.appendChild(div);
    return div;
}
/** 创建加载图片 */
function createLoadingIcon(options) {
    let img = document.createElement('img');
    img.src = options.url || imgLoading;
    img.className = 'c2d-loading-icon';
    img.style.zIndex = '999';
    return img;
}
/** 创建加载文本 */
function createLoadingLabel(options) {
    let span = document.createElement('span');
    span.className = 'c2d-loading-label';
    span.innerHTML = options.label || 'loading...'
    span.style.zIndex = '999';
    return span;
}
export default Cat2DocLoading;
